<script setup>
	import {toRefs,defineProps,watch,ref} from 'vue'
	const props = defineProps({
		//子组件接收父组件传递过来的值
		taskInfo:Object
	}) 
	let datalist = ref()
	const {taskInfo}=toRefs(props)
	// console.log(taskInfo);
	//因为在子组件数据，父组件没有及时的传递，从而不能写在外部，不然获取的值为undefined
	watch(
		()=>taskInfo.value,
		()=> {
		//使用父组件传递过来的值
		datalist.value = [{
				url: 'http://recommender.starsky.fun/tpl/Public/xsm/img/task_finish_count.png',
				text: `${taskInfo.value.apply_num}`
			},
			{
				url: 'http://recommender.starsky.fun/tpl/Public/xsm/img/task_remain_count.png',
				//利用字符串截取转number类型直接计算
				text: `剩余${Number(taskInfo.value.max_num) - Number(taskInfo.value.apply_num)}`
			},
			{
				url: 'http://recommender.starsky.fun/tpl/Public/xsm/img/task_id.png',
				text: '165451'
			},
			{
				url: 'http://recommender.starsky.fun/tpl/Public/xsm/img/task_check_time.png',
				text: '24小时'
			}]
	},{deep:true})

</script>

<template>
	<view class="task-body">
		<view class="task-top">
			<view class="top-left">{{taskInfo?.title}}</view>
			<view class="top-right">{{taskInfo?.price}}</view>
		</view>
		<view class="task-datalist">
			<view class="inner">
				<block v-for="data in datalist" :key="data?.url">
					<view class="item">
						<image :src="data.url" class="icon" mode="scaleToFill" />
						<view class="text">{{ data?.text }}</view>
					</view>
				</block>
			</view>
		</view>
		<view class="task-uid">
			<image src="http://recommender.starsky.fun/Upload/SystemConfig/5f14e8337d511.png"  class="logo-img"
				mode="scaleToFill" />
			<view class="uid-right">
				<view class="top">
				{{taskInfo?.username}}
				</view>
				<view class="bottom">要求等级:
				{{taskInfo?.level_name}}
				</view>
			</view>
		</view>
		<view class="task-center">
			<view class="center-title">任务详情</view>
			<view class="center-text">
			{{taskInfo?.content}}
			</view>
		</view>
	</view>
</template>

<style lang="scss" scoped>
	.task-body {
		.task-top {
			display: flex;
			align-items: center;
			height: 96rpx;
			padding: 0 20rpx;
			font-weight: 600;
			background-color: #fff;

			.top-left {
				flex: 5;
				font-size: 32rpx;
				white-space: nowrap;
				overflow: hidden;
				text-overflow: ellipsis;
			}

			.top-right {
				flex: 1;
				font-size: 36rpx;
				color: #fd6620;
				min-width: 22%;
			}
		}

		.task-datalist {
			height: 80rpx;
			padding: 0 20rpx;
			background-color: #fff;

			.inner {
				display: flex;
				justify-content: space-between;
				height: 64rpx;
				border-top: 2rpx #f0f0f0 solid;
				border-bottom: 2rpx #f0f0f0 solid;

				.item {
					display: flex;
					align-items: center;
					font-size: 26rpx;
					color: #bfbfbf;

					.icon {
						width: 32rpx;
						height: 32rpx;
						margin-right: 8rpx;
					}
				}
			}
		}

		.task-uid {
			display: flex;
			align-items: center;
			height: 128rpx;
			padding: 0 20rpx;
			background-color: #fff;

			.logo-img {
				width: 96rpx;
				height: 96rpx;
				border-radius: 48rpx;
			}

			.uid-right {
				margin-left: 16rpx;
				font-size: 32rpx;

				.top {
					font-size: 30rpx;
					font-weight: 600;
				}
			}
		}

		.task-center {
			margin-top: 16rpx;
			padding-bottom: 32rpx;
			background-color: #fff;

			.center-title {
				height: 80rpx;
				padding: 0 20rpx;
				line-height: 80rpx;
				border-bottom: 2rpx #f0f0f0 solid;
			}

			.center-text {
				padding: 0 44rpx 0 20rpx;
				line-height: 48rpx;
			}
		}
	}
</style>